#include "apue.h"
#include <fcntl.h>

#define BUFFSIZE 4096

int main(int argc, char *argv[]){
	int fd;
	char buf[BUFFSIZE];
	int n;
	
	if(argc != 2)
		err_quit("usage: cat filename\n");
	fd = open(argv[1], O_RDONLY);
	while((n = read(fd, buf, BUFFSIZE)) > 0){
		if(write(STDOUT_FILENO, buf, n) != n)
			err_sys("write error");
	}

	if(n < 0)
		err_sys("read error");
	exit(0);
}
